﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Cloak.NUnit;
using Cloak.Reflection;
using NUnit.Framework;

namespace Ruleweaver.Rules
{
	public class CreatePropertyRule : Behavior
	{
		private CheckRule _rule;
		private PropertyInfo _property;
		private MemberRule _propertyRule;

		protected override void Given()
		{
			_rule = Rule.Check(Reflect.Func<ICheckable<int>, Check<int>>(Checkable.IsPositive));

			_property = typeof(TestTarget).GetProperty("Foo");
		}

		protected override void When()
		{
			_propertyRule = Rule.Property(_property, _rule);
		}

		[Then]
		public void MemberIsProperty()
		{
			Assert.AreEqual(_property, _propertyRule.Member);
		}

		[Then]
		public void MemberTypeIsPropertyType()
		{
			Assert.AreEqual(typeof(int), _propertyRule.MemberType);
		}

		[Then]
		public void RuleIsOriginal()
		{
			Assert.AreEqual(_rule, _propertyRule.Rule);
		}

		[Then]
		public void HasPropertyType()
		{
			Assert.AreEqual(RuleType.Property, _propertyRule.Type);
		}

		private sealed class TestTarget
		{
			public int Foo { get; set; }
		}
	}
}